"""
Fupper - Flickr upload tool for Series 60
Copyright (C) 2006 Teemu Harju

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

Logger class is based on implementation by simo.salminen found on Forum Nokia
http://discussion.forum.nokia.com/forum/showpost.php?p=195757&postcount=3

teemu.harju@gmail.com

$Author: teemu.harju $
$Rev: 26 $
$LastChangedDate: 2007-07-21 05:35:47 +0000 (Sat, 21 Jul 2007) $
"""

import sys
import os
import e32
import appuifw

APPNAME = u"Fupper"
APPVERSION = u"0.9 beta"
APPURL = u"http://fupper.teemuharju.net"
APPABOUT = APPNAME + u" v" + APPVERSION + u"\n" + APPURL
APPPATH = None
DEBUGPATH = None

if e32.in_emulator():
    APPPATH = "c:\\python\\"
    DEBUGPATH = "c:\\"
elif e32.s60_version_info >= (3,0):
    APPPATH = "c:\\private\\" + appuifw.app.uid() + "\\"
    DEBUGPATH = "e:\\debug\\"
else:
    APPPATH = sys.path[0]
    DEBUGPATH = os.path.join(APPPATH, "debug")

class Logger:
    def __init__(self, log_name):
        self.logfile = log_name
        
    def write(self, obj):
        log_file = open(self.logfile, 'a')
        log_file.write(obj)
        log_file.close()
        
    def writelines(self, obj):
        self.write(''.join(list))
        
    def flush(self):
        pass

debug_path = DEBUGPATH
if os.path.exists(debug_path):
    my_log = Logger(os.path.join(debug_path, "debug.txt"))
    sys.stderr = sys.stdout = my_log
    print "debug started"

from graphics import Image
from dialog import wait

loading = 1
appuifw.app.body = appuifw.Canvas()
appuifw.app.body.clear()

#loadingDialog = wait(u"Loading %s..." % APPNAME)

frame_size = (32, 15)
frame_pos = (-(appuifw.app.body.size[0]/2 - frame_size[0]/2),
             -(appuifw.app.body.size[1]/2 - frame_size[1]/2))
text_pos = (-(frame_pos[0] + 10), -(frame_pos[1] + 5))
animation = []
for i in range(1,18):
    animation.append(Image.open(os.path.join(APPPATH,
                                             "animation",
                                             str(i) + ".png")))
import fupper

#loadingDialog.close()
fupper.run()
